#-*- coding: utf-8 -*-
import tensorflow as tf
from model.embedding_matching_net import EMNet
from utils import data_util
from utils import config

conf = config.Config
# model parameter
EPOCH = conf.epoch
BATCH_SIZE = conf.batch_size
LEARNING_RATE = conf.learning_rate
NUM_SAMPLE = conf.num_sample
EMBEDDING_SIZE = conf.embedding_size
ATTENTION_SIZE = conf.attention_size

# data parameter
ITEM_INPUT_LENGTH = conf.item_input_length
OTHER_INPUT_LENGTH = conf.other_input_length
PATH_TFRECORD_TRAIN = conf.path_tfrecord_train
PATH_TFRECORD_VALIDATION = conf.path_tfrecord_validation
PATH_DICT = conf.path_dict
PATH_MODEL = conf.path_model


def main():
    item_dict = data_util.get_dict(PATH_DICT)
    print("record load finished")
    bea_model = EMNet(len(item_dict), EMBEDDING_SIZE, NUM_SAMPLE, LEARNING_RATE, ATTENTION_SIZE, ITEM_INPUT_LENGTH, OTHER_INPUT_LENGTH)

    with tf.Session() as sess:
        # load model
        saver = tf.train.Saver()
        saver.restore(sess, PATH_MODEL)

        feed_dict = {
            bea_model.input_other: [[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]],
            bea_model.input_item:  [[52, 8, 27, 132, 180, 60, 100, 71, 273, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
            bea_model.input_label: [[237]],
            bea_model.input_weight: [[0.04477442, 0.04477442, 0.04477442, 0.04477442, 0.04477442, 0.04477442, 0.02238721, 0.02238721, 0.02238721, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
        }

        # top k value and index
        top_value, top_index = tf.nn.top_k(bea_model.out, k=5, sorted=True)

        predict_value, predict_index = sess.run([top_value, top_index], feed_dict)

        # index to item
        predict_item = data_util.find_key_by_value(item_dict, predict_index)

        print("predict_index: {} \npredict_item: {} \npredict_value:{}".format(predict_index, predict_item, predict_value))


if __name__ == '__main__':
    main()





